package com.link.base.base.questionnaire.controller;

import com.link.core.cllog.LCLogger;
import com.link.base.base.questionnaire.model.QuesAns;
import com.link.base.base.questionnaire.service.QuesAnsService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author unknown
 * @date unknown
 * @comments 问卷
 */
@Controller
@RequestMapping("/link/quesAns")
public class QuesAnsController extends BasicController<QuesAns> {

    @Resource
    private QuesAnsService quesAnsService;

    @Override
    public BasicService<QuesAns> getBasicService() throws Exception {
        return quesAnsService;
    }

    /**
     * 查询一条记录,根据id查询信息，封装返回
     */
    @RequestMapping(value = "/getQuesAnsById")
    @ResponseBody
    public Map<String, Object> getQuesAnsById(QuesAns entity, HttpSession session,
                                              HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            QuesAns record = quesAnsService.getQuesAnsById(entity);
            List<QuesAns> list = new ArrayList<QuesAns>();
            list.add(record);
            this.pushCurrentDataCache(list, session.getId(), "base", false);
            result.put("result", record);
            result.put("success", true);
        } catch (BasicServiceException e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("detailMessage", e.getDetailMessage());
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
